mobile();

function mobile() {
  var winwidth = "";
  var htmlsize = document.getElementsByTagName("html")[0];
  first();

  function first() {
    winwidth = document.documentElement.offsetWidth;
    htmlsize.style.fontSize = winwidth / 7.5 + "px";
  }
  window.onresize = function () {
    first();
  }
}

function getData(url, data) {
  let date = new Date().getTime();
  url += (url.indexOf('?') < 0 ? '?' : '&') + myparam(data) + '&t=' + date;

  return new Promise((resolve, reject) => {
    $.ajax({
      type: 'GET',
      url: url,
      dataType: 'json',
      contentType: 'application/json',
      headers: {
        authorization: 'noAuth'
      },
      // beforeSend: function (xhr) {
      //   xhr.setRequestHeader('content-type', 'application/json')
      //   xhr.setRequestHeader('authorization', 'noAuth')
      // },
      success: function (res) {
        if (res.code === 200 && res.message === 'ok') {
          resolve(res)
        } else {
          console.log('出现错误，错误码: ' + res.code)
        }
      },
      error: function (err) {
        reject(err)
      }
    })
  })
}

function myparam(data) {
  let url = '';
  for (let k in data) {
    let value = data[k] !== undefined ? data[k] : '';
    url += `&${k}=${encodeURIComponent(value)}`
  }
  return url ? url.substring(1) : ''
}
